﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="App.xaml.cs" company="R.V.Kasner">
//   Copyright © 2011 R.V.Kasner
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Owen.Terminal
{
    using System;
    using System.Windows;
    using System.Windows.Threading;

    using Owen.Terminal.Properties;

    public partial class App
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            this.DispatcherUnhandledException += OnDispatcherUnhandledException;

            base.OnStartup(e);
            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();

            this.MainWindow.Closed += OnMainWindowClosed;
        }

        private static void OnMainWindowClosed(object sender, EventArgs e)
        {
            Settings.Default.Save();
        }

        private static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            var s = "Произошла ошибка: " + e.Exception.Message + Environment.NewLine + Environment.NewLine +
                    "Программа будет завершена.";
            MessageBox.Show(s, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            Environment.Exit(1);
        }
    }
}